//
//  Factory.m
//  MoneyBody
//
//  Created by 成都千锋 on 15/8/27.
//  Copyright (c) 2015年 Yes. All rights reserved.
//

#import "MBFactory.h"
//#import "NSString+Size.h"
@implementation MBFactory


+ (UIButton*)createButtonWithName:(NSString*)name
{
    UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 70, 70)];
    [btn setTitle:name forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];
    return btn;
}
+ (NSDateComponents *)getNowTimeCom
{
    NSDate *currDateNow = [NSDate date];
    NSCalendar * cl = [NSCalendar currentCalendar];
    return [cl components:  NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond fromDate:currDateNow];
}
+ (NSDateComponents *)getNowTimeWithDate:(NSDate*)date
{
    NSCalendar * cl = [NSCalendar currentCalendar];
    return [cl components:  NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond fromDate:date];
}
+ (NSInteger)jgDate1Year:(NSInteger)year date1Month:(NSInteger)month date1Day:(NSInteger)day fromDate2:(NSDate*)date2
{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd"];
    NSDate * date1 = [dateFormatter dateFromString:[NSString stringWithFormat:@"%lu-%lu-%lu",year,month,day]];
    return [date1 timeIntervalSinceDate:date2] / (60 * 60 * 24);
}
+ (NSDate*)get1970Date
{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd"];
    return  [dateFormatter dateFromString:@"1970-01-01"];
}
+ (NSDateComponents*)getDCFromNowTo:(NSInteger)ih
{
    NSDate * date = [NSDate dateWithTimeInterval:-ih*60*60*24 sinceDate:[NSDate date]];
    NSCalendar * cl = [NSCalendar currentCalendar];
    return [cl components:  NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond fromDate:date];
}

+ (NSInteger)numberOfStarInString:(NSString*)str
{
    BOOL number = false,bigAlpha = false,smallAlpha = false,sign = false;
    NSArray *lownArr = [self getLownChars];
    NSArray *upArr = [self getUpChars];
    NSArray *numArr = [self getNumberChars];
    for(NSInteger i = 0;i < str.length;i ++)
    {
        if([lownArr containsObject:[NSString stringWithFormat:@"%C",[str characterAtIndex:i]]])
            smallAlpha = YES;
        else if ([upArr containsObject:[NSString stringWithFormat:@"%C",[str characterAtIndex:i]]])
            bigAlpha = YES;
        else if ([numArr containsObject:[NSString stringWithFormat:@"%C",[str characterAtIndex:i]]])
            number = YES;
        
        else
            sign = YES;
    }
    return number + bigAlpha + smallAlpha + sign;
}
/**获取小写字母*/
+ (NSArray*)getLownChars
{
    NSMutableArray * tempArr = [NSMutableArray new];
    for(char ch = 'a';ch <= 'z';ch ++)
        [tempArr addObject:[NSString stringWithFormat:@"%c",ch]];
    return [tempArr copy];
    
}
/**获取大写字母*/
+ (NSArray*)getUpChars
{
    NSMutableArray * tempArr = [NSMutableArray new];
    for(char ch = 'A';ch <= 'Z';ch ++)
        [tempArr addObject:[NSString stringWithFormat:@"%c",ch]];
    return [tempArr copy];
}
/**获取数字*/
+ (NSArray*)getNumberChars
{
    NSMutableArray * tempArr = [NSMutableArray new];
    for(char ch = '0';ch <= '9';ch ++)
        [tempArr addObject:[NSString stringWithFormat:@"%c",ch]];
    return [tempArr copy];
}
+ (void)playSoundEffect:(NSString *)name withCallback:(void (*)(SystemSoundID, void *)) callback {
    NSString *audioFile = [[NSBundle mainBundle] pathForResource:name ofType:nil];
    NSURL *fileUrl = [NSURL fileURLWithPath:audioFile];
    
    SystemSoundID soundID;
    // 在系统中创建一个音效对象并获得其唯一ID
    AudioServicesCreateSystemSoundID((__bridge CFURLRef)(fileUrl), &soundID);
    // 注册在播放完之后执行的回调函数
    // 第二个和第三个参数跟循环播放有关
    // 第五个参数是指向传给回调函数的数据的指针
    AudioServicesAddSystemSoundCompletion(soundID, NULL, NULL, callback, NULL);
    // 播放音效
    AudioServicesPlaySystemSound(soundID);
    // 播放音效并震动
    // AudioServicesPlayAlertSound(soundID);
}

@end
